import {Injectable} from '@angular/core';
import {BaseHttpService} from './base-http.service';
import {ContractLabel, FileTypeObj, PageInfo, SearchCommonVO} from '../types';
import {Observable} from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class FileManageService {

  constructor(public http: BaseHttpService) {
  }

  public getLabelList(param: SearchCommonVO<any>): Observable<PageInfo<ContractLabel>> {
    return this.http.post('/label', param, {needSuccessInfo: false});
  }

  public getTypeList(param: SearchCommonVO<any>): Observable<PageInfo<FileTypeObj>> {
    return this.http.post('/type', param, {needSuccessInfo: false});
  }

  public getLabelDetail(param: { id: number, operationType: number }): Observable<ContractLabel> {
    return this.http.post('/label-detail', param);
  }

  public getLabelTemplate(): Observable<any> {
    return this.http.downZip('/download-template');
  }

  public getExportData(param: SearchCommonVO<any>): Observable<any> {
    return this.http.downZip('/export-data', param);
  }

  public delLabel(ids: number[]): Observable<void> {
    return this.http.post('/del-label', {ids}, {needSuccessInfo: true});
  }

  public addLabel(param: ContractLabel): Observable<void> {
    return this.http.post('/add-label', param, {needSuccessInfo: true});
  }

  public editLabel(param: ContractLabel): Observable<void> {
    return this.http.post('/update-label', param, {needSuccessInfo: true});
  }
}
